Schemas build a framework for documents out of a fairly small set of declarations that describe rules and constraints for elements and attributes. Declarations create vocabulary and set constraints, identify content and indicate where it is to appear. Many schemas can be built using only a combination of element and attribute declarations, while other declarations (like entities and notations) can supplement these core declarations when needed in a particular situation.
Elements and attributes are the core structures of XML, with which document content is built and annotated. Elements and attributes 'mark up' text into easily processed segments, labeled for identification. XML schemas, including DTDs and the various XML schema dialects, describe the structure of those labels and identify (with varying degrees of precision) the material they may contain. Both elements and attributes may contain data types, from simple text types to the complex data types in XML-Data and other schema proposals. Only elements may contain structured content, storing elements within elements and defining potentially complex structure.
Elements and attributes have a number of key differences. Attributes cannot hold subcomponents - no child elements or attributes are allowed within an attribute. Attributes are always assigned to particular elements, while elements can appear inside of any other element as a child element if that element permits it. Attribute values can be set through default or fixed values set in the schema. Elements may contain certain other elements or text, but the actual value of that content cannot be fixed from the schema.
Attributes tend to be simpler, typically holding less (though often just as important) information that annotates an element. In general, elements annotate the content of a document, and attributes annotate elements. In practice, the limitations of attributes restrict their use to some extent, although their ability to have defaults sometimes leads to their use in place of elements.
Schemas can constrain content for elements and attributes, requiring that the content within them meet certain criteria. XML Instance can handle a number of data types from the XML-Data schema proposal, in addition to the built-in types provided by XML 1.0. Only the built-in XML types are supported by XML 1.0 validating parsers (and only for attributes), but processors supporting the newer schemas should support a fuller selection of types.
In addition to identifying attribute types, attribute type declarations include a default value for each attribute. Default values are used by schema developers to provide values for attributes, require that document authors provide values, or fix the value permanently. This makes it much easier to ensure that information appears when it should without requiring an enormous amount of extra markup within documents.
Copyright 2000 Extensibility, Inc.
Suite 250, 200 Franklin Street, Chapel Hill, North Carolina 27516